package com.wilmar.designer.util;

import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.Reader;
import java.io.Writer;

/**
 * Utility for XSLT.
 * <p/>
 * User: Sean
 * Date: Jan 4, 2010
 * Time: 1:07:04 AM
 */
public class XsltUtils {

    public static void transform(Reader xsltReader, Reader sourceReader, Writer targetWriter) throws TransformerException {
        Transformer transformer = createTransformer(xsltReader);

        transformer.transform(new StreamSource(sourceReader), new StreamResult(targetWriter));
    }

    public static Transformer createTransformer(Reader xsltReader) throws TransformerConfigurationException {
        Source xsltSource = new StreamSource(xsltReader);

        TransformerFactory transformerFactory = TransformerFactory.newInstance();

        return transformerFactory.newTransformer(xsltSource);
    }
}
